//
//  UIImageView+Extensions.swift
//  微博
//
//  Created by hejinyin on 2017/9/8.
//  Copyright © 2017年 WangQiang. All rights reserved.
//

import UIKit

//MARK: =========== 动画 ===========
extension UIImageView{

    static let kRotationAnimate = "rotationAnimate"
    
    open func startRotationAnimate(duration:CFTimeInterval = 2.0){
        
        var animate = layer.animation(forKey: UIImageView.kRotationAnimate) as? CABasicAnimation
        if animate == nil {
            animate = CABasicAnimation.init(keyPath: "transform.rotation")
            animate?.toValue = 2 * Double.pi
            animate?.repeatCount = MAXFLOAT
            animate?.duration = duration
            animate?.isRemovedOnCompletion = false
            layer.add(animate!, forKey: UIImageView.kRotationAnimate)
        }
        
    }
    
    open func stopRotationAnimate(){
        layer.removeAnimation(forKey: UIImageView.kRotationAnimate)
    }
}
